﻿<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <!-- <a-form-model-item label="更新时间" prop="UpdateTime">
          <a-input v-model="entity.UpdateTime" autocomplete="off" placeholder="更新时间" />
        </a-form-model-item> -->

        <!-- <a-form-model-item label="规则主表ID" prop="ParentId">
          <a-input v-model="entity.ParentId" autocomplete="off" placeholder="规则主表ID" />
        </a-form-model-item>
        <a-form-model-item label="销售产品ID" prop="SalePId">
          <a-input v-model="entity.SalePId" autocomplete="off" placeholder="销售产品ID" />
        </a-form-model-item> -->
        <a-form-model-item label="销售品名" prop="SalePName">
          <a-input v-model="entity.SalePName" autocomplete="off" placeholder="销售品名" />
        </a-form-model-item>
        <a-form-model-item label="销售品数量" prop="SalePQuantity">
          <a-input v-model="entity.SalePQuantity" autocomplete="off" placeholder="销售品数量" />
        </a-form-model-item>
        <a-form-model-item label="返料产品ID" prop="GiftPId">
          <a-input v-model="entity.GiftPId" autocomplete="off" placeholder="返料产品ID" />
        </a-form-model-item>
        <a-form-model-item label="返料品名" prop="GiftPName">
          <a-input v-model="entity.GiftPName" autocomplete="off" placeholder="返料品名" />
        </a-form-model-item>
        <a-form-model-item label="返料品数量" prop="GiftPQuantity">
          <a-input v-model="entity.GiftPQuantity" autocomplete="off" placeholder="返料品数量" />
        </a-form-model-item>
        <a-form-model-item label="备注" prop="Remark">
          <a-input v-model="entity.Remark" autocomplete="off" placeholder="备注" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/GiftManagement/GMM_GiftMaterialRuleDetails/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/GiftManagement/GMM_GiftMaterialRuleDetails/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
